import { _decorator, Component, Node } from 'cc';
import { RoomInfo } from '../../../tsrpc/shared/type/RoomInfo';
import { Label } from 'cc';

const { ccclass, property } = _decorator;

export type RoomListItemOptions = {
    roomInfo: RoomInfo,

    onClick: (v: {
        serverUrl: string,
        roomId: number
    }) => void
};

@ccclass('RoomListItem')
export class RoomListItem extends Component {

    @property(Label)
    labelName!: Label;
    @property(Label)
    labelPeople!: Label;

    private _options!: RoomListItemOptions;
    public get options(): RoomListItemOptions {
        return this._options!;
    }
    public set options(v: RoomListItemOptions) {
        this._options = v;

        this.labelName.string = v.roomInfo.roomId.toString();
        this.labelPeople.string = `人数:${v.roomInfo.currentNum}/${v.roomInfo.maxNum}`;
    }
    start() {

    }

    update(deltaTime: number) {
        
    }

    onClickJoin() {
        this.options.onClick({
            serverUrl: "",//this.options.roomInfo.serverUrl,
            roomId: this.options.roomInfo.roomId
        })
    }
}


